import { homeBrand, homeBanner } from '@/api/home'
const state = {
  brandList: [], // 品牌数据
  bannerList: [] // 轮播图数据
}
const mutations = {
  setBrandList (state, value) {
    state.brandList = value
  },
  setBannerList (state, value) {
    state.bannerList = value
  }
}
const actions = {
  async getBrandList ({ commit, state }) {
    if (state.brandList.length === 0) {
      const res = await homeBrand(10)
      commit('setBrandList', res.result)
      return res.result
    }
    return state.brandList
  },
  async getBannerList (store) {
    if (store.state.bannerList.length) {
      return store.state.bannerList
    }
    const res = await homeBanner()
    store.commit('setBannerList', res.result)
    return res.result
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
